<@pp.dropOutputFile/>
<#include "../common/util.ftl">
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign app = doc.artifactid?replace(".", "/")>
<#assign package = table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name = "/" + package  + "/" + fileName + "ServiceSqliteImplTest.vb"/>
<#compress>
<#list table.fields as field>
	<#assign typePackage = getTypePackage(field.type)>
	<#if typePackage?length != 0>Imports ${typePackage}</#if>
</#list>
</#compress>
Imports System.Text
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports ${app}
Imports Stone.Common
Imports log4net.Config

<TestClass()>
Public Class ${fileName}ServiceSqliteImplTest
    Shared service As ${fileName}Service = Nothing
    Private log As log4net.ILog = log4net.LogManager.GetLogger(Reflection.MethodBase.GetCurrentMethod().DeclaringType)

	<ClassInitialize()>
    Public Shared Sub ClassInit(ByVal context As TestContext)
        BasicConfigurator.Configure()
    End Sub

    <TestInitialize()>
    Public Sub init()
        service = New ${fileName}ServiceSqliteImpl()
        service.init()

        For i As Integer = 0 To 9
            addOne()
        Next
    End Sub

    <TestCleanup()>
    Public Sub cleanup()
		service.cleanup()
    End Sub

    <TestMethod()>
    Public Sub testInit()
        service.init()
    End Sub

    Private Function addOne() As String
        Dim o As ${fileName} = New ${fileName}()

		<#list table.fields as field>
		o.${field.name?cap_first} = ${generateVBData4VB(field.type, field_index)}
		</#list>
		o.Id = System.Guid.NewGuid.ToString()

        Dim oc As Outcome = service.create(o)
		log.Info(oc.Detail)
		
		Return o.Id
    End Function

    <TestMethod()>
    Public Sub testCreate()
        Dim oc As Outcome = service.create(Nothing)
		log.Info(oc.Detail)
		Assert.IsFalse(oc.Success)
		
        Dim o As ${fileName} = New ${fileName}()

		<#list table.fields as field>
		o.${field.name?cap_first} = ${generateVBData4VB(field.type, field_index)}
		</#list>

        oc = service.create(o)
		log.Info(oc.Detail)
        Assert.IsTrue(oc.Success)

    End Sub

    <TestMethod()>
    Public Sub testGetPage()
        Dim oc As Outcome = service.getPage(1, 3, Nothing)
		log.Info(oc.Detail)
		Assert.IsTrue(oc.Success)
        Dim os As List(Of ${fileName}) = oc.Data
        Assert.IsNotNull(os)
        Assert.AreEqual(3, os.Count)

        For Each i In os
            System.Console.WriteLine(i.Id)
        Next

    End Sub

    <TestMethod()>
    Public Sub testSize()
		Dim oc As Outcome = service.Size(Nothing)
		Assert.IsTrue(oc.Success)
        Dim o As Integer = oc.Data
        Assert.AreEqual(10, o)
    End Sub

    <TestMethod()>
    Public Sub testGetOne()
		Dim id As String = addOne()
		Dim params As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
		params.Add("Id", id)
		
		Dim oc As Outcome = service.getOne(Nothing)
		log.Info(oc.Detail)
		Assert.IsFalse(oc.Success)
		
		oc = service.getOne(params)
		log.Info(oc.Detail)
		Assert.IsTrue(oc.Success)
        Dim o As ${fileName} = oc.Data
        Assert.IsNotNull(o)
        Assert.AreEqual(id, o.Id)

    End Sub
	
    <TestMethod()>
    Public Sub testUpdate()
		Dim id As String = addOne()
		Dim params As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
		params.Add("Id", id)
		
        Dim o As ${fileName} = service.getOne(params).Data
		Assert.IsNotNull(o)
		<#list table.fields as field>
		o.${field.name?cap_first} = ${generateVBData4VB(field.type, field_index + 100)}
		</#list>
		o.Id = id
		Dim oc As Outcome = service.update(o)
		log.Info(oc.Detail)
		Assert.IsTrue(oc.Success)
        Assert.AreEqual(1, oc.Data)

    End Sub

	<TestMethod()>
    Public Sub testDelete()
        Dim oc As Outcome = service.delete(Nothing)
		log.Info(oc.Detail)
        Assert.IsTrue(oc.Success)
		Assert.AreEqual(10, oc.Data)
    End Sub
End Class

</#list>